/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Mar 16, 2012  11:39:12 AM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : jpa.service.promis.common
 * File Name : VwSyncRcvdInstallmentServices.java
 * TODO
 */
package jpa.service.promis.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;

import org.apache.log4j.Logger;

import promis.utility.CommonService;

import jpa.entitys.promis.common.VwSyncRcvdInstallment;
import jpa.service.common.JPAService;

/**
 * @author chatree
 *
 */
public class VwSyncRcvdInstallmentServices extends JPAService {
	
	
	private static final Logger log = Logger.getLogger(VwSyncRcvdInstallmentServices.class);

	/**
	 * @param em
	 */
	public VwSyncRcvdInstallmentServices(EntityManager em) {
		super(em);
		// TODO Auto-generated constructor stub
	}


	public List<VwSyncRcvdInstallment> findAll() throws Exception 
	{
		return super.ConvertToYoureObject(super.findAll("VwSyncRcvdInstallment.findAll"));
	}
	
	public VwSyncRcvdInstallment findById(String id) throws Exception {		
		
		return super.ConvertToYoureObject(super.find(id, "VwSyncRcvdInstallment.findById"));				
	}	
	
	public List<VwSyncRcvdInstallment> findByDocumentNo(String company, String project, String documentNo, String status, String syncIsstaging) throws Exception {
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();				
		mapWhereValue.put("company", company);  			log.info("company = " + company);
		mapWhereValue.put("project", project);				log.info("project = " + project);
		mapWhereValue.put("documentNo", documentNo);		log.info("documentNo = " + documentNo);
		mapWhereValue.put("status", status);				log.info("status = " + status);
		if(!CommonService.IsNull(syncIsstaging))
		{
			mapWhereValue.put("syncIsstaging", syncIsstaging);	log.info("syncIsstaging = " + syncIsstaging);
			return super.ConvertToYoureObject(super.find("VwSyncRcvdInstallment.findByDocumentNo", mapWhereValue));	
		}else
			return super.ConvertToYoureObject(super.find("VwSyncRcvdInstallment.findByDocumentNoStaNull", mapWhereValue));
		
	}
	
	public List<VwSyncRcvdInstallment> findNoPaymentTypeByDocumentNo(String company, String project, String documentNo, String status, String syncIsstaging) throws Exception {
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();				
		mapWhereValue.put("company", company);  			log.info("company = " + company);
		mapWhereValue.put("project", project);				log.info("project = " + project);
		mapWhereValue.put("documentNo", documentNo);		log.info("documentNo = " + documentNo);
		mapWhereValue.put("status", status);				log.info("status = " + status);
		mapWhereValue.put("syncIsstaging", syncIsstaging);	log.info("syncIsstaging = " + syncIsstaging);
		
		return super.ConvertToYoureObject(super.find("VwSyncRcvdInstallment.findNoPaymentTypeByDocumentNo", mapWhereValue));
		
	}
	
	public List<VwSyncRcvdInstallment> findHasPaymentTypeByDocumentNo(String company, String project, String documentNo, String status, String syncIsstaging) throws Exception {
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();				
		mapWhereValue.put("company", company);  			log.info("company = " + company);
		mapWhereValue.put("project", project);				log.info("project = " + project);
		mapWhereValue.put("documentNo", documentNo);		log.info("documentNo = " + documentNo);
		mapWhereValue.put("status", status);				log.info("status = " + status);
		mapWhereValue.put("syncIsstaging", syncIsstaging);	log.info("syncIsstaging = " + syncIsstaging);
		
		return super.ConvertToYoureObject(super.find("VwSyncRcvdInstallment.findHasPaymentTypeByDocumentNo", mapWhereValue));
		
	}
	
	@Deprecated
	public List<VwSyncRcvdInstallment> findNoPaymentTypeByRefDocNo(String company, String project, String refDocNo, String status, String syncIsstaging) throws Exception {
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();				
		mapWhereValue.put("company", company);  			log.info("company = " + company);
		mapWhereValue.put("project", project);				log.info("project = " + project);
		mapWhereValue.put("refDocNo", refDocNo);		log.info("refDocNo = " + refDocNo);
		mapWhereValue.put("status", status);				log.info("status = " + status);
		mapWhereValue.put("syncIsstaging", syncIsstaging);	log.info("syncIsstaging = " + syncIsstaging);
		
		return super.ConvertToYoureObject(super.find("VwSyncRcvdInstallment.findNoPaymentTypeByRefDocNo", mapWhereValue));
		
	}
	
	public List<VwSyncRcvdInstallment> findByRefDocumentNo(String company, String project, String refDocumentNo, String status, String syncIsstaging) throws Exception {
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();				
		mapWhereValue.put("company", company); 				log.info("company = " + company);
		mapWhereValue.put("project", project);				log.info("project = " + project);
		mapWhereValue.put("refContractNo", refDocumentNo);	log.info("refContractNo = " + refDocumentNo);
		mapWhereValue.put("status", status);				log.info("status = " + status);
		if(!CommonService.IsNull(syncIsstaging)){
			mapWhereValue.put("syncIsstaging", syncIsstaging);	log.info("syncIsstaging = " + syncIsstaging);
			return super.ConvertToYoureObject(super.find("VwSyncRcvdInstallment.findByRefDocumentNo", mapWhereValue));
		}else{
			return super.ConvertToYoureObject(super.find("VwSyncRcvdInstallment.findByRefDocumentNoWithOutStag", mapWhereValue));
		}
	}
}
